package function;

import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

import login.LoginFrame;

public class UserFrame extends JFrame{
	
	private JButton b_bill,b_card,b_out,b_exit;//账单，水电卡购买，退房
	private JLabel l_hello,l_content,l_content1,l_content2,l_content3;//文本
	private String Username;
	private int bill;
	private BillFrame b ;
	public UserFrame(String Username) {
		this.Username = Username;
		b=new BillFrame("select user.id,name,age,user.uno,user.hno,水费,电费,燃气费,取暖费,物业费,房租 from user,bill,house where user.hno = house.hno and bill.id = user.id and type = '业主' and name = '"+Username+"' and (水费!=0 OR 电费!=0 OR 燃气费!=0 OR 取暖费!=0 OR 物业费!=0 OR 房租!=0)",Username);
		b.setVisible(false);
		this.bill = b.getUser().length;
		this.setSize(600,500);
		this.setTitle("业主界面");
		this.setLocation(500,150);
		init();
		this.setVisible(true);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
	
	public void init() {
		Font fontBB = new Font("宋体",Font.BOLD,25);
		Font fontB = new Font("宋体",Font.BOLD,12);
		b_bill = new JButton("账单");
		b_bill.setFont(fontB);
		b_bill.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				new BillFrame("select user.id,name,age,user.uno,user.hno,水费,电费,燃气费,取暖费,物业费,房租 from user,bill,house where user.hno = house.hno and bill.id = user.id and type = '业主' and name = '"+Username+"' and (水费!=0 OR 电费!=0 OR 燃气费!=0 OR 取暖费!=0 OR 物业费!=0 OR 房租!=0)",Username);
				setVisible(false);
			}
			
		});
		b_card = new JButton("一卡通购买");
		b_card.setFont(fontB);
		b_card.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				
				new CardFrame("select * from card where id = (select id from user where name = '"+Username+"')",Username);
				setVisible(false);
			}
			
		});
		b_out = new JButton("退房");
		b_out.setFont(fontB);
		b_out.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				
				JPanel p = new JPanel();
				if(b.getUser().length == 0) {
					int n = JOptionPane.showConfirmDialog(p,"您确定要进行退房操作","确认退房",JOptionPane.YES_NO_OPTION);
					if(n == JOptionPane.YES_OPTION) {
						
						new CheckOutFrame("select user.id,name,type,sex,age,hno from user where name = '"+Username+"'",Username);
						setVisible(false);
						
					}
				}else {
					JOptionPane.showMessageDialog(p,"您还有未缴费的账单，暂不可使用此功能！","提示框",JOptionPane.WARNING_MESSAGE);
				}
			}
			
		});
		
		b_exit = new JButton ("退出登录");
		b_exit.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				new LoginFrame();
				setVisible(false);
			}
			
		});
		
		l_hello = new JLabel("您好，",JLabel.CENTER);
		l_hello.setFont(fontBB);
		l_content = new JLabel("尊敬的业主先生！",JLabel.CENTER);
		l_content.setFont(fontBB);
		l_content1 = new JLabel("欢迎使用业主系统，您可在此进行缴费",JLabel.CENTER);
		l_content1.setFont(fontBB);
		l_content2 = new JLabel("和购买一卡通！",JLabel.CENTER);
		l_content2.setFont(fontBB);
		l_content3 = new JLabel("祝您生活愉快！",JLabel.CENTER);
		l_content3.setFont(fontBB);
		this.setLayout(null);
		JPanel p = new JPanel();
		p.setLayout(new GridLayout(1,4,5,5));
		p.add(b_bill);
		p.add(b_card);
		p.add(b_out);
		p.add(b_exit);
		p.setBounds(15,10,550,30);
		this.add(p);
		
		p = new JPanel();
		p.add(l_hello);
		p.setBounds(20,60,100,50);
		this.add(p);
		
		p = new JPanel();
		p.add(l_content);
		p.setBounds(20,135,350,50);
		this.add(p);
		
		p = new JPanel();
		p.add(l_content1);
		p.setBounds(60,195,500,50);
		this.add(p);
		
		p = new JPanel();
		p.add(l_content2);
		p.setBounds(15,255,240,50);
		this.add(p);
		
		p = new JPanel();
		p.add(l_content3);
		p.setBounds(300,350,350,50);
		this.add(p);
		
	}
	
	
}
